import 'dart:async';

import 'package:async/async.dart';
import 'package:get/get.dart';

import '../../route/app_pages.dart';

///闪屏启动业务都在这里处理
class SplashController extends GetxController {
  final AsyncMemoizer memo = AsyncMemoizer<void>();

  @override
  void onInit() {
    super.onInit();
    memo.runOnce(_initFunction);
  }

  //此处可以做一个变换 之类的比如说 换图片呀 缩放动画呀 这些
  void _changeActive() {}

  Future<void> _initFunction() async {
    final Timer t = Timer.periodic(
      const Duration(seconds: 1),
      (Timer t) => _changeActive(),
    );
    //simulate some long running operation
    await Future<void>.delayed(
      const Duration(seconds: 1),
    );
    //cancel the timer once we are done
    t.cancel();

    await Get.toNamed(AppRoutes.appMain);
  }
}
